<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>未处理意见建议</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <link rel="stylesheet" href="../../layui/font/iconfont.eot">
    <script src="../../js/jquery-3.4.1.js"></script>
    <script src="../../mock/mock/mock-min.js"></script>
    <script src="../../mock/mock1.js"></script>
    <style>
        .chaxun {
            display: inline;
            width: 90%;
            margin-right: 20px;
        }
        
        .dignbuanniu {
            margin: 15px 0;
        }
        
        .dingbuyihang {
            padding: 0px 10px;
            width: 90%;
        }
        /*水平竖直居中  */
        
        .juzhong {
            margin-top: 30px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .xingzhengcunxinxitianjia {
            width: 60%;
        }
        
        .hanggao {
            margin: 40px 0px;
        }
        
        .xiangqingtitle {
            color: #999;
        }
        
        .xiangqingcontent {
            text-align: center;
            width: 50%;
        }
        
        .xiangqingjianjie {
            width: auto;
            text-align: left;
            text-indent: 40px;
            padding: 9px 40px;
        }
        
        .layui-btn- {
            margin-left: 2px !important;
        }
    </style>
</head>

<body>
    <div style="padding: 20px; background-color: #f2f2f2">
        <div class="layui-card layui-col-space15" style="padding: 20px; background-color: #fff">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="saixuan">
                    <div class="layui-row">
                        <div class="layui-col-xs1 layui-col-sm1 layui-col-md1 dignbuanniu">
                        </div>

                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">
                        </div>

                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">
                            <label class="layui-form-label dingbuyihang">
                                <select id="qu" name="areaId" lay-verify="required"  lay-filter="qu">
                                    <option value="">地区筛选(区/县)</option>
                                </select>
                            </label>
                        </div>

                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">
                            <label class="layui-form-label dingbuyihang">
                                <select id="zhen1" name="townid" lay-verify="required"  lay-filter="zhen1">
                                    <option value="">地区筛选(镇/街道)</option>
                                </select>
                            </label>
                        </div>
                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">

                            <label class="layui-form-label dingbuyihang">
                        <select name="villageId" lay-verify="required" id="cun1" >
                            <option value="">地区筛选(村)</option>
                        </select>
                            </label>
                        </div>
                        <div class="layui-col-xs2 layui-col-sm2 layui-col-md2 dignbuanniu">
                            <input type="text" name="keyWords" required lay-verify="required" placeholder="查询内容或字段" autocomplete="off" class="layui-input chaxun">
                        </div>
                        <div class="layui-col-xs1 layui-col-sm1 layui-col-md1 dignbuanniu">
                            <button type="button" class="layui-btn" onclick="chaxun()">
                                <i class="layui-icon layui-icon-search"></i>&nbsp;&nbsp;查询
                              </button>
                        </div>

                    </div>
                </form>
                <!-- 底部表格 -->
                <table class="layui-hide" id="test" lay-filter="test"></table>
            </div>
        </div>
    </div>
    <!-- 村 -->
    <script type="text/html" id="barDemo3">
        <a class="layui-btn layui-btn-xs" lay-event="up1">向镇反馈</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="chuli1">处理反馈</a>
    </script>
    <!-- 镇 -->
    <script type="text/html" id="barDemo2">
        <a class="layui-btn layui-btn-xs layui-btn-" lay-event="up2">向区反馈</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-" lay-event="chuli2">处理反馈</a>
        <a class="layui-btn layui-btn-xs layui-btn-" lay-event="down2">驳回村反馈</a>
        <a href=""></a>
    </script>
    <!-- 区 -->
    <script type="text/html" id="barDemo1">
        <a class="layui-btn layui-btn-xs" lay-event="down3">驳回镇反馈</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="chuli3">处理反馈</a>
    </script>

    <script src="../../layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

    <script>
        var currentTownId = "";
        var currentVillageId = "";
        var option;
        var table;
        layui.use(['table', 'form'], function() {
            table = layui.table;
            form = layui.form;

            option = {
                    elem: '#test',
                    url: url + "general/feedback/queryUntreated",
                    toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
                    headers: {
                        token: localStorage.getItem('token')
                    },
                    where: {},
                    limits: [10, 20, 50, 100, 200, 500],
                    size: "lg",
                    request: {
                        pageName: "currrntPage",
                        limitName: "size",
                    },
                    defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                        title: '提示',
                        layEvent: 'LAYTABLE_TIPS',
                        icon: 'layui-icon-tips'
                    }],
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    parseData: function(res) {
                        //res 即为原始返回的数据
                        return {
                            code: 0, //解析接口状态
                            msg: res.msg, //解析提示文本
                            count: res.data.count, //解析数据长度
                            data: setdata(res.data.ntreatedlist), //解析数据列表
                            // data: setdata(res), //解析数据列表
                        };
                    },
                    title: '用户数据表',
                    cols: [
                        [{
                            type: "numbers",
                            title: '#',
                        }, {
                            field: 'townname',
                            title: '所属街道',
                            align: "center"
                        }, {
                            field: 'villagename',
                            title: '所属村',
                            align: "center"
                        }, {
                            field: 'title',
                            title: '反馈标题',
                            align: "center"
                        }, {
                            field: 'content',
                            title: '反馈内容',
                            align: "center"
                        }, {
                            fixed: 'right',
                            title: '操作',
                            toolbar: localStorage.getItem('level') === "3" ? '#barDemo3' : localStorage.getItem('level') === "2" ? "#barDemo2" : "#barDemo1",
                            align: "center"
                        }]
                    ],
                    page: true
                }
                // table.render(option);
            tableIns = table.render(option);

            //添加筛选条件
            // 区生成
            areas.forEach(item => {
                    // console.log($('#zhen1')[0].innerHTML)
                    $('#qu')[0].innerHTML += ` <option value="` + item.id + `">` + item.name + `</option>`
                })
                // 镇生成
            towns.forEach(item => {
                    // console.log($('#zhen1')[0].innerHTML)
                    $('#zhen1')[0].innerHTML += ` <option value="` + item.id + `">` + item.name + `</option>`
                })
                // 村生成
            form.on('select(zhen1)', function(data) {
                $('#cun1').empty()
                $('#cun1')[0].innerHTML += ` <option value="">地区筛选(村)</option>`
                villages.forEach(item => {
                    if (item.townId == data.value) {
                        $('#cun1')[0].innerHTML += ` <option value="` + item.id + `">` + item.name + `</option>`
                    }
                })
                form.render('select', "saixuan")
            });
            // 1.区选择
            form.on('select(qu)', function(data) {
                $('#zhen1').empty()
                $('#zhen1')[0].innerHTML += ` <option value="">请选择所属镇</option>`
                towns.forEach(item => {
                    if (item.areaId == data.value) {
                        $('#zhen1')[0].innerHTML += ` <option value="` + item.id + `">` + item.name + `</option>`
                    }
                })
                form.render('select', "tianjia")
            });

            form.render('select', "saixuan")

            //监听行工具事件
            table.on('tool(test)', function(obj) {
                console.log(obj)
                switch (obj.event) {
                    case "up1":
                        xiangshangfankui(obj)
                        break;
                    case "chuli1":
                        window.location.href = "./chulihuifu.html?id=" + obj.data.id;
                        break;
                    case "up2":
                        xiangshangfankui(obj)
                        break;
                    case "chuli2":
                        window.location.href = "./chulihuifu.html?id=" + obj.data.id;
                        break;
                    case "down2":
                        xiangxiafankui(obj)
                        break;
                    case "down3":
                        xiangxiafankui(obj)
                        break;
                    case "chuli3":
                        window.location.href = "./chulihuifu.html?id=" + obj.data.id;
                        break;
                }
                console.log(obj);
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('真的退回么', function(index) {
                        obj.del();
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {}
            });
        });

        function setdata(data) {
            console.log(data);
            data.forEach(item => {
                item.townname = gettown(item.townId).name
                item.villagename = getvillage(item.villageId).name
            });
            return data
        }

        // 查询方法
        function chaxun() {
            var data = form.val("saixuan");
            option.where.areaId = data.areaId
            option.where.townId = data.townid
            option.where.villageId = data.villageId
            option.where.keywords = data.keyWords
            table.reload("test", option);
        }

        function xiangshangfankui(obj) {
            layer.open({
                type: 1,
                title: "删除",
                offset: "auto",
                content: `<div style="font-size: 15px;line-height: 100px;height: 100px;text-align: center;">你确定要向上反馈当前项吗</div>`,
                area: ["350px", "200px"],
                btn: ["确定", "取消"], //可以无限个按钮
                btn1: function() {
                    var data = {}
                    data.id = obj.data.id
                    data.upMessage = obj.data.upMessage
                    $.ajax({
                        url: url + "general/feedback/upfeedback",
                        data: data,
                        method: "post",
                        success: function(data) {
                            console.log(data)
                            if (data.code === 200) {
                                layer.closeAll();
                                table.render(option)
                                layer.msg(data.msg)
                            } else {
                                table.render(option)
                                layer.msg("操作失败")
                            }
                        },
                        error: function(err) {
                            layer.msg("操作失败")
                        }
                    })
                },
                btn2: function() {
                    layer.msg("已取消操作");
                },
            });
        }

        function xiangxiafankui(obj) {
            layer.open({
                type: 1,
                title: "删除",
                offset: "auto",
                content: `<div style="font-size: 15px;line-height: 100px;height: 100px;text-align: center;">你确定要退回当前反馈项吗</div>`,
                area: ["350px", "200px"],
                btn: ["确定", "取消"], //可以无限个按钮
                btn1: function() {
                    var data = {}
                    data.id = obj.data.id
                    $.ajax({
                        url: url + "general/feedback/downfeedback",
                        data: data,
                        method: "post",
                        success: function(data) {
                            console.log(data)
                            if (data.code === 200) {
                                layer.closeAll();
                                table.render(option)
                                layer.msg(data.msg)
                            } else {
                                table.render(option)
                                layer.msg("操作失败")
                            }
                        },
                        error: function(err) {
                            layer.msg("操作失败")
                        }
                    })
                },
                btn2: function() {
                    layer.msg("已取消操作");
                },
            });
        }
    </script>

</body>

</html>